<?php
session_start();
require_once("includes/header.php");
?>

<?php
$name = $password = "";


if (!empty($_POST)) {
    $name = $_POST['name'];
    $password = $_POST['password'];

    $db = file_get_contents("data/users.json");
    $db_array = json_decode($db, true);
    $data = $db_array[$name];

    if ($name == $data['jsonEmail'] && $password == $data['jsonPassword']) {
        session_unset();
        $_SESSION['username'] = $_POST['name'];
        #print welcome message and redirect
        echo "Login  Success. Now redirect to MyFitness Page...";
        echo "<script language=\"JavaScript\">
window.setTimeout(\"location='MyFitness.php'\", 2000);
</script>";
    } else {

        #print welcome message and redirect
        echo "You need to log in. Now redirect to Login Page...";
//        echo "<script language=\"JavaScript\">
//window.setTimeout(\"location='login.php'\", 2000);
//</script>";
    }
}

?>

<?php
require_once("includes/footer.php");
?>



